home *** CD-ROM | disk | FTP | other *** search
/ Aminet 25 / Aminet 25 (1998)(GTI - Schatztruhe)[!][Jun 1998].iso / Aminet / dev / c / MemPools.lha / realloc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-03-13  |  1.9 KB  |  86 lines

  1. /**
  2. ***  MemPools:  malloc() replacement using standard Amiga pool functions.
  3. ***  Copyright  (C)  1994    Jochen Wiedmann
  4. ***
  5. ***  This program is free software; you can redistribute it and/or modify
  6. ***  it under the terms of the GNU General Public License as published by
  7. ***  the Free Software Foundation; either version 2 of the License, or
  8. ***  (at your option) any later version.
  9. ***
  10. ***  This program is distributed in the hope that it will be useful,
  11. ***  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ***  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. ***  GNU General Public License for more details.
  14. ***
  15. ***  You should have received a copy of the GNU General Public License
  16. ***  along with this program; if not, write to the Free Software
  17. ***  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. ***
  19. ***
  20. ***  This file contains the realloc() replacement.
  21. ***
  22. ***
  23. ***  Computer:  Amiga 4000
  24. ***
  25. ***  Compilers: gcc 2.7.2
  26. ***             SAS/C 6.58
  27. ***
  28. ***
  29. ***  Author:    Jochen Wiedmann
  30. ***             Am Eisteich 9
  31. ***       72555 Metzingen
  32. ***             Germany
  33. ***
  34. ***             Phone: (0049) 7123 14881
  35. ***             Internet: jochen.wiedmann@uni-tuebingen.de
  36. ***
  37. ***  Bugfixes
  38. ***  Updates:   Matthias Andree
  39. ***             Stormstr. 14
  40. ***             58099 Hagen
  41. ***             Germany
  42. ***
  43. ***             Phone: +49-(0)23 31-96 30 72
  44. ***
  45. ***             E-Mail: mandree@dosis.uni-dortmund.de
  46. ***
  47. **/
  48.  
  49.  
  50.  
  51.  
  52. /*
  53.     Include files and compiler specific stuff
  54. */
  55. #include <stdlib.h>
  56. #include <string.h>
  57.  
  58. #include "mempools.h"
  59.  
  60.  
  61. void *realloc(void *oldPtr, size_t size)
  62.  
  63. {
  64.     void *ptr;
  65.     size_t oldSize=0;
  66.  
  67.     if (oldPtr) {
  68.     if (!size) {
  69.         free(oldPtr);
  70.         return(NULL);
  71.     }
  72.     oldSize = ((memBlock *) oldPtr)[-1].size;
  73.     if (oldSize  >=  size) {
  74.         return(oldPtr);
  75.     }
  76.     }
  77.     if ((ptr = malloc(size))) {
  78.     if (oldPtr) {
  79.         memcpy(ptr, oldPtr, oldSize);
  80.         free(oldPtr);
  81.     }
  82.     }
  83.  
  84.     return(ptr);
  85. }
  86.